<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            模具维护任务列表
        </div>
    </header>
    <script id="chkBillTemp" type="text/x-dot-template">

        {{~ it:value:index}}
        <li class="aui-list-item" onclick="setTask('{{= it[index].taskId }}','{{= it[index].taskCode }}','{{= it[index].planCode }}','{{= it[index].chkGid }}','{{= it[index].beginDate }}','{{= it[index].taskState }}','{{= it[index].taskResult }}','{{= it[index].endDate }}');">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-inner ">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title aui-font-size-14">
                            任务编码：{{= it[index].taskCode }}
                        </div>
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        维护模板名称：{{= it[index].chkName }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        模具条码：{{= it[index].rsBarcode }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        实际开始时间：{{= it[index].actualBeginDate }}
                    </div>
                </div>
            </div>
        </li>
        {{~}}

    </script>

    <div class="aui-content" style="margin-top:50px;">
        <div class="aui-form" style="margin-top:15px;">
            <div class="aui-content aui-margin-b-15">
                <ul class="aui-list aui-form-list">
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="font-size: 17px;">模具条码</div>
                            <input type="text" class="aui-input" placeholder="请 扫描/输入 模具条码"
                                style="width: 80%;font-size: 14px;" id="rsCode">
                            <i class="aui-input-addon aui-iconfont aui-icon-scan " style="font-size: 1.6rem"
                                onclick="toScanner();"></i>
                        </div>
                    </li>

                    <!-- <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="width:150px">计划开始时间</div>
                            <div class="aui-list-item-input" onclick="timePicker();">
                                <input type="text" placeholder="选择日期" style="padding-left: 35px;" class="aui-input"
                                    id="dateTime">
                            </div>
                        </div>
                    </li> -->

                </ul>
            </div>
        </div>
    </div>
    <div style="width:100%;margin-top:2%;"></div>
    <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSearch()">查询</div>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-media-list" id="taskList">

        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var boxnum = "";
    var type = ""
    apiready = function () {
        type = api.pageParam.type;
        $("#rsCode").focus();
        idSelector = "rsCode";

    };

    //时间选择器
    function timePicker() {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#dateTime").val(date);
                doSearch();
            }
        });
    }
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

  /*   //扫描
    function toScanner(inputId) {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            var sm = ret;
          
            if (inputId == 'rsCode') {
                $("#rsCode").blur();
                var text = document.getElementById("rsCode");
                text.value = sm;

              //  $("#rsCode").val(ret);
                doSearch();
            }
        });
    } */

     //扫描条码
     function toScanner(flag) {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function(ret, err) {

            var sm = ret;
            
                var text = document.getElementById("rsCode");
                text.value = sm;
                doSearch();

        });
    }

    //箱号监听回车事件
    $("#rsCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            if (tm != null && tm != "" && tm != undefined) {
                doSearch();
            }
        }
    });


    //查询资源维护任务
    function doSearch() {

        //箱号
        var rsCode = $("#rsCode").val();
        var dateTime = $("#dateTime").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/geChkTaskByRsCode";
        var data = {
            values: {
                rsCode: rsCode,
                un: un,
                dateTime: dateTime,
                rsClass:'模具',
                type:type,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    var evaluation = doT.template($api.dom('#chkBillTemp').innerHTML);
                    $api.dom('#taskList').innerHTML = evaluation(list);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //选则返回函数
    function setTask(taskId, taskCode, planCode, chkGid, beginDate, taskState, taskResult, endDate) {
        api.closeWin();
        var name = api.pageParam.name;
        api.execScript({
            name: 'rsMoldMntTask',
            script: 'setTask("' + taskId + '","' + taskCode + '","' + planCode + '","' + chkGid + '","' + beginDate + '","' + beginDate + '","' + taskResult + '","' + endDate + '")'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>